import { postBodyRequest, getRequest, putRequest } from '@/libs/axios'

/**
 * 根据问诊记录生成初始病历
 * @param {string} consultationId - 问诊ID
 * @returns {Promise} 返回生成的病历记录
 */
export const generateMedicalRecord = (consultationId) => {
  return postBodyRequest(`/medical-records/generate/${consultationId}`)
}

/**
 * 获取病历详情
 * @param {string} id - 病历ID
 * @returns {Promise} 返回病历详情
 */
export const getMedicalRecord = (id) => {
  return getRequest(`/medical-records/${id}`)
}

/**
 * 更新病历
 * @param {string} id - 病历ID
 * @param {Object} record - 病历数据
 * @returns {Promise} 返回更新后的病历
 */
export const updateMedicalRecord = (id, record) => {
  return putRequest(`/medical-records/${id}`, record)
}

/**
 * 获取当前用户的病历列表
 * @returns {Promise} 返回病历列表
 */
export const getCurrentUserMedicalRecords = () => {
  return getRequest('/medical-records/current-user')
}

/**
 * 获取指定用户的病历列表
 * @param {string} userId - 用户ID
 * @returns {Promise} 返回病历列表
 */
export const getUserMedicalRecords = (userId) => {
  return getRequest(`/medical-records/user/${userId}`)
}

/**
 * 获取医生的病历列表
 * @param {string} doctorId - 医生ID
 * @returns {Promise} 返回病历列表
 */
export const getDoctorMedicalRecords = (doctorId) => {
  return getRequest(`/medical-records/doctor/${doctorId}`)
}

/**
 * 创建新病历
 * @param {Object} record - 病历数据
 * @returns {Promise} 返回创建的病历
 */
export const createMedicalRecord = (record) => {
  return postBodyRequest('/medical-records', record)
}

/**
 * 获取病历修订历史
 * @param {string} id - 病历ID
 * @returns {Promise} 返回病历修订历史列表
 */
export const getMedicalRecordHistory = (id) => {
  return getRequest(`/medical-records/${id}/history`)
}

/**
 * 根据问诊ID获取或创建病历
 * @param {string} consultationId - 问诊ID
 * @returns {Promise} 返回病历详情
 */
export const getMedicalRecordByConsultation = (consultationId) => {
  return getRequest(`/medical-records/consultation/${consultationId}`)
}

/**
 * 获取患者当前病历
 * @param {string} patientId - 患者ID
 * @returns {Promise} 返回患者当前病历
 */
export const getCurrentMedicalRecord = (patientId) => {
  return getRequest(`/medical-records/patient/${patientId}/current`)
}

/**
 * 获取患者历史病历列表
 * @param {string} patientId - 患者ID
 * @returns {Promise} 返回患者历史病历列表
 */
export const getPatientHistoryRecords = (patientId) => {
  return getRequest(`/medical-records/patient/${patientId}/history`)
}

/**
 * 获取医生科室的病历列表
 * @returns {Promise} 返回科室病历列表
 */
export const getDepartmentRecords = () => {
  return getRequest('/medical-records/department')
} 
 